/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package hojadetrabajo3;

/**
 *
 * @author CarlosAndre
 */
import java.math.BigDecimal;
public class Insertion {
    static int x=1;
    public static void insertionSort(Comparable[] data)
    // pre: 0 <= n <= data.length
    // post: values in data[0..n-1] are in ascending order
    {
    int numSorted = 1; // number of values in place
    int index; // general index
    int n=data.length;
    while (numSorted < n)
    {
        // take the first unsorted value
        Comparable temp = data[numSorted];
        // ...and insert it among the sorted:
        for (index = numSorted; index > 0; index--)
        {
            
            if (temp.compareTo(data[index-1])<0)
            {
                data[index] = data[index-1];
                } 
            else {
                    break;
                }
        }
        // reinsert value
        data[index] = temp;
        numSorted++;
    }
    }
}
   

